package com.example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    private static final Logger logger = LoggerFactory.getLogger(WebConfig.class);

    public WebConfig() {
        logger.info("试一下可以不");
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        logger.info("成功加载了");

        registry.addMapping("/**") // 对所有路径应用CORS设置
                .allowedOrigins("*") // 允许这个来源的请求
                .allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的HTTP方法
                .allowCredentials(true); // 允许发送cookies
    }
}
